package com.neu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neu.po.Post;
import com.neu.po.ResponseResult;
import com.neu.service.PostService;

@RestController
@RequestMapping("post")
public class PostController {

	@Autowired
	private PostService postService;
	
	@RequestMapping("insert")
	public ResponseResult insert(@RequestBody Post post) {
		ResponseResult result = new ResponseResult();
		
		result.setData(postService.insert(post));
		
		return result;
	}
	
	@RequestMapping("update")
	public ResponseResult update(@RequestBody Post post) {
		ResponseResult result = new ResponseResult();
		
		result.setData(postService.update(post));
		
		return result;
	}
	
	@RequestMapping("delete")
	public ResponseResult delete(int id) {
		ResponseResult result = new ResponseResult();
		
		result.setData(postService.delete(id));
		
		return result;
	}
	
	@RequestMapping("getByName")
	public ResponseResult getByName(String pname) {
		ResponseResult result = new ResponseResult();
		
		result.setData(postService.getByName(pname));
		
		return result;
		
	}
	
	@RequestMapping("getPaged")
	public ResponseResult getPaged(int pageNum, int pageSize,String keyword) {
		ResponseResult result = new ResponseResult();
		
		result.setData(postService.getPaged(pageSize, pageNum,keyword));
		
		return result;
		
	}
	
	@RequestMapping("getAll")
	public ResponseResult getAll() {
		ResponseResult result = new ResponseResult();
		
		result.setData(postService.getAll());
		
		return result;
	}
	
}
